home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / sound.621 < prev    next >
Text File  |  1992-02-06  |  6KB  |  74 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fswiss Helvetica;}
  2. \paperw11760
  3. \paperh7200
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 MIDI msg_receive threads MusicKit\
  8. \
  9. Q:  
  10. \fc0 As I understand it, t
  11. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 he MIDI timer and I/O is handled with
  12. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  
  13. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 the 
  14. \b msg_receive
  15. \b0  call
  16. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 , which
  17. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  is a kind of polling 
  18. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 that
  19. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  happens
  20. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  
  21. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 whenever the application has time to poll. 
  22. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  
  23. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 B
  24. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ut if the application is busy with other things,
  25. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  
  26. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 might not 
  27. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 the 
  28. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 polling 
  29. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 interval
  30. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  become too great or too variable, which could have
  31. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  
  32. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 a 
  33. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 musically unacceptable
  34. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  effect?\
  35. \
  36. A:  
  37. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 It
  38. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 '
  39. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 s true that your application must go into a 
  40. \b msg_receive
  41. \b0  to receive MIDI.  However, it
  42. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 '
  43. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 s possible to structure your application so that there
  44. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  i
  45. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 s a separate Mach thread that does nothing or little else than service this 
  46. \b msg_receive
  47. \b0 .  
  48. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 This should provide the response time you need.  
  49. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 For example, if you use the Music Kit, there
  50. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  i
  51. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 s a new feature in 2.0 that allows the Music Kit performance (and, hence, the MIDI 
  52. \b msg_receive
  53. \b0 ) to run in a separate thread from the graphics event loop.  
  54. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 (This feature is also useful for non-MIDI performances, such as those using DSP synthesis.) 
  55. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 Alternatively, if you don't use the Music Kit, you can fork your own thread to handle the MIDI asynchronous
  56. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ly
  57. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  to the event loop.   \
  58. \
  59. Running the Music Kit in a separate thread will make it unlikely that graphics will prevent you from receiving your MIDI in a timely fashion.  However, the Music Kit scheduler (just like the Appkit event loop) is non-preemptive—there's no absolute limit to how much can be done before going back to the 
  60. \b msg_receive
  61. \b0 .   Therefore, if you write your own Performer, Instrument, or NoteFilter subclass, make it as efficient as possible, because you won't receive MIDI until you exit your code.   In principle, the way to get the fastest MIDI response is to have your own separate thread loop processing the MIDI, without using the Music Kit.  However, if that thread does much processing other than receiving MIDI, using the Music Kit would probably be just as efficient (and easier to program). The important thing is to get back to the
  62. \b  msg_receive
  63. \b0  as quickly as possible, whether in the Music Kit, the Appkit, or your own thread.\
  64. \
  65. As an example of a multi-threaded Music Kit application, see /NextDeveloper/Examples/MusicKit/PerformerExample (not in release 1.0).  As an example of Music Kit MIDI processing, see /NextDeveloper/Examples/MusicKit/MidiEcho.  As a complex example of using the Music Kit, see /NextDeveloper/Examples/MusicKit/Ensemble (not in release 1.0). Finally, if you don't use the Music Kit, see the Cthreads documentation for how to run the MIDI loop in a separate thread. \
  66. \
  67.  
  68. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600 QA621\
  69. \
  70. Valid for 1.0\
  71. Valid for 2.0\
  72. \
  73.  
  74.